#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    Solution(vector<int>& nums)
    {
        srand((unsigned int)time(NULL));
        int n = nums.size();
        for (int i = 0; i < n; ++i)
        {
            _numIndexMap[nums[i]].push_back(i);
        }
    }

    int pick(int target)
    {
        int n = _numIndexMap[target].size();

        if (n == 0)
        {
            return -1;
        }

        return _numIndexMap[target][rand() % n];
    }

private:
    std::unordered_map<int, std::vector<int>> _numIndexMap;
};